<template>
  <div id="app">
    <el-card shadow="always">
      {{studentSearch}}

      <el-table
          :data="studentList"
          style="width: 100%">
        <el-table-column
            label="学号"
            prop="sid"
            align="center"
            width="180">
        </el-table-column>
        <el-table-column
            label="姓名"
            align="center"
            prop="sname">
        </el-table-column>
        <el-table-column
            label="性别"
            align="center"
            prop="sex">
        </el-table-column>
        <el-table-column
            label="年龄"
            align="center"
            prop="age">
        </el-table-column>
        <el-table-column
            label="住址"
            align="center"
            prop="addr">
        </el-table-column>
        <el-table-column
            label="所在班级"
            align="center"
            prop="cname">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
                size="mini"
                @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>


    </el-card>

  </div>
</template>

<script>
import studentApi from "@/api/student"
export default {
  data() {
    return {
      studentList: [],
      page:1,
      pageSize:5,
      total:100,
      searchStudent:{},
      studentSearch: {},
      classesList: [],
      dialogFormVisible:false,
      formLabelWidth:'100px',
      student: {},
      title: '添加学生',
    }
  },
  created() {


    this.search()
  },

  methods: {

    findStudents(){
      this.$axios.get('/student/list.do')
          .then(res => {
            // this.studentList = res.data;
            console.log("数据：",res.data)
            this.studentList = res.data
          })


    },

    async findByPage(){

      // })

      const {data:res} = await studentApi.findByPage(this.page,this.pageSize)
      this.studentList = res.rows
      this.total = res.total
    },

    async findClasses(){
      const {data:res} = await classesApi.findClasses()
      this.classesList = res
    },

    async search(){
      const {data} = await studentApi.findStudents()
      console.log(data)
      this.studentList = data.data.students
    },

    editStudent(){
      this.dialogFormVisible = true
    },

    async saveStudent(){
      const {data:res} = await studentApi.save(this.student)
      if (res.code === 200){
        this.$message({
          type: 'success',
          message: res.message
        })

        this.dialogFormVisible = false

        this.search()
      }else {
        this.$message({
          type: 'error',
          message: res.message
        })
      }
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },

    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      // this.findByPage(this.page,this.pageSize)
      this.search()
    },

    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page = val;
      // this.findByPage(this.page,this.pageSize)
      this.search()
    }
  }
}
</script>
<style>
.el-card{
  width: 90%;
  //margin: 0 auto;
}
#app{
  display: flex;
  justify-content: center;
}
.el-pagination{
  text-align: right;
  margin-top: 15px;
}
</style>
